/*
 * @Date: 2023-02-14 09:45:44
 * @LastEditTime: 2023-05-05 23:02:52
 * @FilePath: /nlk/src/utils/tools/project.ts
 * 介绍:
 */
import useClipboard from "vue-clipboard3";
import toast from "@@/hooks/toast";
import { i18n } from "@@/language/index";

/**
 * * 省略文本
 * @param text 省略文本
 * @param config 省略配置
 */
export function omitText(
  text: string | null | undefined,
  config: [number, string, number] = [5, "...", 5]
) {
  if (!text) return "----";
  let res = text.slice(0, config[0]);
  res += config[1];
  res += text.slice(text.length - config[2]);
  return res;
}
/**
 * 复制文本
 * @param text 复制的内容
 * @returns 成功失败
 */
export async function copyText(text: string): Promise<boolean> {
  const { toClipboard } = useClipboard();
  //@ts-ignore
  const { t } = i18n.global;
  try {
    await toClipboard(text);
    toast.success(t("fu-zhi-cheng-gong"));
    return true;
  } catch (e) {
    toast.error(t("fu-zhi-shi-bai"));
    return false;
  }
}
